<?php
//{{ include
include 'abstract.php';
//}}

class api_digu extends api_abstract
{
    /**
     * 嘀咕API的域名
     *
     * @var string
     * @access private
     */
    private $host = 'http://apidev.digu.com/';

    protected function _init() {
        $this->global = array(
				'public_timeline' => array( 'since' => '', 'since_id' => '', 'count' => '', 'page' => '' ),
				'friends_timeline' => array( 'since' => '', 'since_id' => '', 'count' => '', 'page' => '' ),
				'user_timeline' => array( 'userIdOrName' => '' ),
				'show' => array( 'id' => '' )
            );
    }

    public function get_statuses($actionName=null, $args=array()) {
        $actionName = isset($actionName)?$actionName:'public_timeline';
        $option = $this->global[$actionName];
        $param = array();
        foreach( $option as $key => $opt ) {
            if($args){
                if( $args[$key]!=$opt && $args[$key]!='' ) $param[] = $key . '=' . $args[$key];
            } else {
                $param[] = $key . '=' . $opt;
            }
        }
        $host = $this->host . 'statuses/' . $actionName . '.' . $this->config['format'] . '?' . implode('&amp;', $param);
        return $this->exec_url($host);
    }

    public function send_msg(&$data, $images = false) {
        $fanfou_url = 'http://api.fanfou.com/statuses/update.' . $this->config['format'];
        $digu_url = 'http://api.digu.com/statuses/update.' . $this->config['format'];

        $fanfou_vars = array(
            'status' => $data['text']
        );
        $digu_vars = array(
            'content' => urlencode($data['text'])
        );
        $ch = curl_init();
        curl_setopt( $ch, CURLOPT_HEADER, 1 );
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt( $ch, CURLOPT_POST, 1 );
        curl_setopt( $ch, CURLOPT_USERPWD, "ithink:roysky" );
        curl_setopt( $ch, CURLOPT_URL, $digu_url );
        curl_setopt( $ch, CURLOPT_POSTFIELDS, $digu_vars );
        $return_digu = curl_exec($ch);
        curl_close($ch);

        //dump($return_fanfou);
        dump($return_digu);
    }

}

function dump($v) {
    echo '<pre>';
    print_r($v);
    echo '</pre>';
}
